import store from '@/store'

// const base_url = 'http://127.0.0.1:5000'
// const base_url = 'http://192.168.13.61:5000'
// const base_url = 'http://192.168.10.143:5000'
const base_url = 'https://report.lswkdb.com'
// const base_url = 'http://192.168.199.233:5000'
// 登陆账号
export const login = async (data) => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/oauth/token`,
    method: 'POST',
    data: data
  })
  return !error && res.data
}

export const fetchUser = async () => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/user`,
    header: {'Authorization': `Bearer ${store.state.token['access_token']}`}
  })
  return !error && res.data
}

// 注册
export const register = async (data) => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/users`,
    method: 'POST',
    data: data
  })
  return !error && res.data
}

// 设置账号
export const setting_user = async (data) => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/user`,
    method: 'POST',
    header: {'Authorization': `Bearer ${store.state.token['access_token']}`},
    data: data
  })
  return !error && res.data
}

// 设置账号单位
export const setting_user_company = async (data) => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/user/company`,
    method: 'POST',
    header: {'Authorization': `Bearer ${store.state.token['access_token']}`},
    data: data
  })
  return !error && res.data
}

// 获取验证码
export const fetchCode = async (data) => {
  let [error, res] = await uni.request({
    url: `${base_url}/api/sms`,
    method: 'POST',
    data: data
  })
  return !error && res.data
}